home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM Gold
/
Light ROM Gold.iso
/
arexx
/
movscene.lwm
< prev
next >
Wrap
Text File
|
1995-05-01
|
20KB
|
693 lines
/* CMD: Move Scene v3.0
* Move Lightwave Scene file and all that it is used in it, to a new
* place. Useful for transfering scenes to another computer.
* It will move all of your images, rearrange your scene file so
* that the objects will load from the new directory you specified.
* It will also take into account if you are moving your scenes into
* 3.5" disks and measure how much space is left, requesting new
* disks and initialize them in Amiga or IBM format.
*
* To run the macro, you will need these Workbench programs in C:
* copy, makedir, list, delete, format and rename.
*
* To use PC disks, you should have CrossDos (included in WB 2.1+) and
* installed for your internal drive (DF0).
*
* If using lha, you should have lha - if you prefer another lha
* compressor, just use your favorite editor to change "LHA" to
* the compressor you like.
* You could probably modify LHA to work with ARJ, or other PC compressor.
*
* If using compress, you should also have compress.b16 in C:.
*
* NOTE: This version 3.0 is still beta. The reason I decided to
* release it was that many people seemed to need it.
* In this version, if you use any type of compression, you
* will not be able to load the file into LW later. You will
* have to rename all the files. This might be fixed later.
* Also, if you have two different objects that start with the
* same 8 characters, the macro will not detect this, and consider
* you are always talking about the same object. This will also
* be fixed in the final version (These two things require some
* good rewritting of the code, so you'll have to wait).
* Bugs, comments and suggestions to ggarramuno@sicoar1.satlink.net
*
* 8/94 Version 1.0 - By Gonzalo Garramuno (C) 1994
* 11/94 Version 2.0 - By Gonzalo Garramuno (C) 1994
* > fixed bug with objects bigger than 65,535 bytes.
* > added option to turn off copying image and
* image sequences.
* > added option for changing the paths of the
* scene and object files to point to the new
* place.
* > added option for multiple disks, formatting
* them as needed.
* > added lha compression if lha is in C:
* note: if using lha, avoid files with bad
* names (ie. those that have wildcards
* characters in them, such as ?,#,),etc)
*
* 3/95 Version 3.0 beta (C) 1995 Gonzalo Garramuno
* > added shortening files to 8 characters and
* changing spaces to underscores.
* > added compress compression for SGI compatibility.
* watch out for wrong characters: !, etc.
*/
call addlib "LWModelerARexx.port", 0
call addlib "rexxsupport.library", 0, -30, 0
signal on error
signal on syntax
sysnam = 'Move Scene'
version = 'Move Scene v3.0'
statfil="T:move.scene"
image = 3
path = 1
disk = 1
dnum = 1
comp = 0
short = 0
repl = 0
cant = 0
nfil = 0
if (exists(statfil)) then do
if (~open(state, statfil, 'R')) then break
if (readln(state) ~= version) then break
l1 = readln(state)
l2 = readln(state)
image = readln(state)
path = readln(state)
disk = readln(state)
comp = readln(state)
short = readln(state)
repl = readln(state)
call close state
end
if l1="L1" then do
/* If you have Lightwave installed somewhere else other than
Toaster: then change the path below */
l1="Toaster:3D/Scenes"
name1=""
l2="ram:"
name2=""
end
else do
filenam="/"
s=2
if lastpos("/",l1)=0 then do
filenam=":"
s=1
end
name1=right(l1,length(l1)-lastpos(filenam,l1))
l1=left(l1,pos(name1,l1)-s)
filenam="/"
s=2
if lastpos("/",l2)=0 then do
filenam=":"
s=1
end
if length(l2)=lastpos(filenam,l2) then filenam=""
name2=right(l2,length(l2)-lastpos(filenam,l2))
l2=left(l2,pos(name2,l2)-s)
end
filenam=getfilename("-- Lightwave Scene --",l1,name1)
if filenam ="(none)" then exit
call REQ_BEGIN("Move Scene")
id_disk=REQ_ADDCONTROL("Copy to?",'CH',"Directory",
"Multiple"d2c(160)"DF0: Multiple"d2c(160)"PC0:")
id_image=REQ_ADDCONTROL("Copy Images?",'CH',"No Images"d2c(160)"only
Images"d2c(160)"and"d2c(160)"Sequences")
id_path=REQ_ADDCONTROL("Change Paths",'B')
id_comp=REQ_ADDCONTROL("Compression",'CH',"None LHA Compress")
id_short=REQ_ADDCONTROL("Shorten filenames to 8 chrs?",'B')
id_repl=REQ_ADDCONTROL("Change spaces to underscores?",'B')
call REQ_SETVAL(id_disk,disk)
call REQ_SETVAL(id_image,image)
call REQ_SETVAL(id_path,path)
call REQ_SETVAL(id_comp,comp)
call REQ_SETVAL(id_short,short)
call REQ_SETVAL(id_repl,repl)
ok=REQ_POST()
If ok~=1 Then exit
disk = REQ_GETVAL(id_disk)
image = REQ_GETVAL(id_image)
path = REQ_GETVAL(id_path)
comp = REQ_GETVAL(id_comp)
short = REQ_GETVAL(id_short)
repl = REQ_GETVAL(id_repl)
select
when disk=1 then do
Drawer=getfilename("-- Drawer to Create --",l2,name2)
if Drawer ="(none)" then exit
Drawer = short(Drawer,"")
end
when disk=2 then Drawer="DF0:"
otherwise Drawer="PC0:"
end
/* Save preferences just in case */
if (open(state, statfil, 'W')) then do
call writeln state, version
call writeln state, filenam
call writeln state, Drawer
call writeln state, image
call writeln state, path
call writeln state, disk
call writeln state, comp
call writeln state, short
call writeln state, repl
call close state
end
if disk>1 then call askdisk()
if comp = 2 then Drawer = Drawer || ".lha"
if comp = 3 then Drawer = Drawer || ".Z"
/* Number of Images in Scene and/or Objects */
img=0
if (exists(filenam)) then do
/* Erase if there was a previous one by mistake */
address command
if (disk=1)&(exists(Drawer)) then do
if notify(2,"Delete "||Drawer"?")=0 then exit
'delete "'Drawer'" all >NIL:'
end
obj=0
if (~open(state, filenam, 'R')) then exit
parse value readln(state) with type .
if type~="LWSC" then do
Bummer("Not a Lightwave ASCII Scene!")
end
else do while eof(state)=0
type=readln(state)
if left(type,11)="LoadObject " then do
obj=obj+1
object.obj = substr(type,12)
newobj.obj = short(object.obj,"OBJ")
end
/* Handle images in scene file
* Background, Foreground, Alpha, Displacement and Clip maps */
if image > 1 then do
l=pos(" ",type)
if l=0 then l=1
if (left(type,l)="BGImage "),
|(left(type,l)="FGImage "),
|(left(type,l)="FGAlphaImage "),
|(left(type,l)="TextureImage ") then do
img = img + 1
image.img = substr(type,l+1)
newimg.img = short(image.img,"")
end
end
end
call close state
/* Make dir and copy scene file to it */
if disk=1 then call makdir(Drawer)
say "Okay, " disk
newnam = short(filenam,"LSC")
call cop(filenam,Drawer,newnam)
if disk=1 then Drawer=Drawer||"/"
/*****************************************/
/* Copy all objects to Objects Directory */
/*****************************************/
if obj>0 then do
call METER_BEGIN(obj+1,"Moving Objects")
call makdir(Drawer"Objects")
do i=1 to obj
call METER_STEP()
call cop(object.i,Drawer"Objects",newobj.i)
if image > 1 then do
if (~open(state, object.i, 'R')) then exit
seq=0
/* Type is an array, to avoid problems with big objects */
do while eof(state) = 0
seq = seq + 1
type.seq = readch(state,65535)
end
call close state
do t=1 to seq
l=0
l2=1
do while (l<length(type.t))&(length(type.t)>3)
/* Search for "IMG" in object, which tells us about an image file */
l = pos("IMG",type.t,l2)
if l ~= 0 then do
l2 = pos(d2c(0),type.t,l+4)
l2 = l2-l-5
check = 0
do s = 1 to img
if substr(type.t,l+5,l2)=image.s then check = 1
if substr(type.t,l+5,l2)="(none)" then check = 1
end s
if check=0 then do
img = img+1
image.img = substr(type.t,l+5,l2)
newimg.img = short(image.img,"")
end
l2 = l+l2
l = l2
end
else l = length(type.t)
end
end t
end
end i
end
call METER_END
/*******************************************************/
/* Copy all images (and sequences) to Images directory */
/*******************************************************/
if img>0 then do
call makdir(Drawer"Images")
call METER_BEGIN(img+1,"Moving Images")
call METER_STEP
do i = 1 to img
call METER_STEP
/* Handle sequences: create special dir */
if (right(image.i,11) = " (sequence)")&(image=3) then do
name1 = CheckSeq(image.i)
image.i = left(image.i,length(image.i)-11)
call makdir(Drawer"Images/"||left(name1,length(name1)-1))
call cop(image.i"#?",Drawer"Images/"name1,newimg.i)
end
/* Handle image files */
else do
call cop(image.i,Drawer"Images",newimg.i)
end
end i
call METER_END
end
if path = 1 then do
name1=""
/***************************/
/* Modify Scene file paths */
/***************************/
if disk>1 then do
Drawer = "Disk"
call checkdisk2(files.1)
name1="1:"
end
l=search(filenam)
file=Drawer||name1||right(filenam,length(filenam)-l)
file=short(file,"LSC")
if (~open(state, filenam, 'R')) then break
if (~open(state2, file, 'W')) then break
do while eof(state)=0
type = readln(state)
if left(type,11)="LoadObject " then do
file = delstr(type,1,11)
l = search(file)
i = checkdisk(file)
type = "LoadObject " || Drawer || i || "Objects/"
name = short(right(file,length(file)-l),"OBJ")
type = type || name
end
if image > 1 then do
l = pos(" ",type)
if (left(type,l)="BGImage "),
|(left(type,l)="FGImage "),
|(left(type,l)="FGAlphaImage "),
|(left(type,l)="TextureImage ") then do
file = delstr(type,1,l)
type = left(type,l)
l = search(file)
i = checkdisk(file)
type = type || Drawer || i || "Images/"
name = short(right(file,length(file)-l),"")
type = type || name
end
end
call writeln state2, type
end
call close state
call close state2
/***************************************/
/* Now modify the objects' images path */
/***************************************/
call METER_BEGIN(obj+1,"Modifying paths")
do i=1 to obj
call METER_STEP()
l = search(object.i)
t = checkdisk2(object.i)
file = Drawer || t || "Objects/"
name = short(right(object.i,length(object.i)-l),"OBJ")
file = file || name
if (~open(state, object.i, 'R')) then break
if (~open(state2, file, 'W')) then break
do while eof(state)=0
type = readch(state,10000)
l=0
l2=1
do while (l<length(type))&(length(type)>3)
l = pos("IMG",type,l2)
if l ~= 0 then do
l2 = pos(d2c(0),type,l+4)
l2 = l2-l-5
img = img+1
file = substr(type,l+5,l2)
if file~="(none)" then do
t=search(file)
dnum = checkdisk(file)
say "FILE:" file
name1 = short(CheckSeq(file),"")
say "NAME1:" name1
name = short(right(file,length(file)-t),"")
say "NAME:" name
file = Drawer || dnum || "Images/" || name1,
|| name
file = left(type,l+3)|| d2c(length(file)+2) || file
type = substr(type,l+l2+5)
end
else file = ""
type = file || type
l2 = l+l2
l = l2
end
else l = length(type)
end
call writech state2, type
end
call close state
call close state2
end i
call METER_END()
end
file = SHOWLIST("V",,"|")
end
else do
Bummer("Can't open Scene file : "filenam)
end
exit
/* Ask to insert new disk */
askdisk: PROCEDURE EXPOSE dnum Drawer size obj img
t=notify(3,"@Please insert a new disk in DF0:",,
"!The disk will be formatted. All Information will be lost",,
"Are you sure you want to continue?")
if t=0 then exit
call METER_BEGIN(2,"Formatting disk")
call METER_STEP
address command
"format DRIVE" '"'Drawer'"' "NAME Disk"dnum "NOICONS >NIL:"
call METER_END()
if img>0 then call makdir(Drawer||"Images")
else do
if obj>0 then call makdir(Drawer||"Objects")
end
/* Get info on size of all disks */
"info >RAM:info.testfile "Drawer
/* Find the size of the disk we are working with */
if (~open(test, "RAM:info.testfile", 'R')) then break
do i=1 to 3
text = readln(test)
end i
text = readln(test)
text = word(text,2)
size = left(text,length(text)-1)*1000
call close test
"delete ram:info.testfile > NIL:"
return
/* Makedir procedure */
makdir: PROCEDURE
parse arg source
address command
if ~exists(source) then do
"makedir" '"'source'"'
end
return
/* Insert disk message */
insdisk: PROCEDURE EXPOSE Drawer
parse arg num
loop:
call notify(1,"Please insert Disk" num "in any drive")
/* Check that the user put the right disk in before going on */
Drives = SHOWLIST("V",,"|")
l = pos(UPPER(Drawer || num || "|"),Drives)
if l = 0 then call loop
return
/* Copy procedure. Checks for disk size */
Cop:
/* PROCEDURE EXPOSE disk Drawer cant size dnum obj img,
nfil files. fdisk. lha image */
parse arg source, dest, altsrc
if comp = 2 then do
source = lharc(source)
end
if comp = 3 then do
source = compress(source)
end
altsrc = GetName(altsrc)
if disk > 1 then do
add = 0
if (right(source,2) = "#?")&(image=3) then do
/* Get file size for all the images in sequence
* All the images of a sequence should fit in the same device.
*/
"list" source ">ram:info.testfile files quick lformat=%l"
if (~open(test, "RAM:info.testfile", 'R')) then break
do while eof(test)=0
text = readln(test)
if text~="" then add = add + text
end
call close test
"delete ram:info.testfile > NIL:"
end
else do
t = statef(source)
add = word(t,2)
end
if add > size then do
call notify(1,"You will not be able to fit the",,
"current scene on floppys. Use the Directory",,
"Option with a backup program or try compressing",,
"your objects before running the macro.")
exit
end
if (cant + add) > size then do
dnum = dnum + 1
cant = 0
call askdisk()
end
cant = cant + add
/* Add another file to list */
nfil = nfil + 1
files.nfil = source
fdisk.nfil = dnum
end
if ~exists(source) then do
call notify(1,"One of the files used in the",,
"scene is no longer in the same place",,
"or it has been deleted. Go into Layout",,
"and manually change the scene.")
exit
end
name=Getname(source)
/* File exists on destination: maybe due to PC's only 8 characters
if exists(dest) then do
if rena<2 then do
call REQ_BEGIN("File "dest" already exists!")
id_rena=REQ_ADDCONTROL("",CH,"Rename"d2c(160)"it",
"Rename"d2c(160)"all","Cancel")
call REQ_SETVAL(id_rena,2)
call REQ_END()
rena=REQ_GETVAL(id_rena)
if rena=3 then exit 1
end
index=1
do while exists(dest||name)
index=index+1
end
newname=left(name,8)||index
dest=dest||name
end */
address command
"copy" '"'source'"' '"'dest'/'altsrc'"'
/* Erase ram: .lha and .Z files */
if comp > 1 then 'delete "'source'" all >NIL:'
return
/* Find disk number for a file */
Checkdisk: PROCEDURE EXPOSE disk nfil files. fdisk. image
parse arg filenam
if disk = 1 then return ""
if (right(filenam,11) = " (sequence)")&(image=3) then do
filenam = left(filenam,length(filenam)-11)||"#?"
end
do i=1 to nfil
if filenam = files.i then return fdisk.i || ":"
end i
return
/* Check disk in drive to see if it is the one where file is.
* If not, ask for disk */
Checkdisk2: PROCEDURE EXPOSE disk nfil files. fdisk. Drawer
parse arg filenam
t = checkdisk(filenam)
if t = "" then return ""
t=left(t,1)
Drives = SHOWLIST("V",,"|")
l = pos(UPPER(Drawer || t || "|"),Drives)
if l = 0 then call insdisk(t)
t = t || ":"
return t
CheckSeq: PROCEDURE EXPOSE image
parse arg filenam
test = ""
if (right(filenam,11) = " (sequence)")&(image=3) then do
filenam = left(filenam,length(filenam)-11)
l = length(filenam) - search(filenam)
test = right(filenam,l)||"/"
end
return test
Search: PROCEDURE
parse arg filenam
i = lastpos("/",filenam)
l = lastpos(":",filenam)
if l>i then i=l
return i
/* Strip extensions and get name of file only */
GetName: PROCEDURE
parse arg name
l = search(name)
if n ~= 0 then do
name=right(name,length(name)-l)
say name
end
return name
/* Compress files to ram: before copying them */
Lharc: PROCEDURE
parse arg source
l = search(source)
file = "ram:" || right(source,length(source)-l)
'LHA -x a "'file||'.lha"' '"'source'" >NIL:'
'rename "'file||'.lha"' '"'file'"'
return file
compress: PROCEDURE EXPOSE short repl
parse arg source
l = search(source)
l2 = short
short = 1
file = short("ram:" || right(source,length(source)-l),"")
short = l2
'copy "'source'" "'file'"'
'compress.b16 "'file'"'
file = file || ".Z"
say file
return file
Short: PROCEDURE EXPOSE short repl
parse arg file, ext
l = search(file)
l2 = 8
if (l + 8) > length(file) then l2 = length(file) - l
if repl = 1 then file = translate(file,"_-"," .")
if ext ~= "" then ext = "." || ext
if short = 1 then file = left(file,l) || substr(file,l+1,l2) || ext
return file
Bummer:
parse arg etxt
t=Notify(1,'!Rexx Script Error','@'ETxt)
exit
syntax:
error:
call end_all
t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
exit